package main

import (
	"fmt"
	"io/ioutil"
	"math/rand"
	"net/http"
	"time"
)

func main() {
	url_params := []string{"衣服", "娃娃", "好看", "水杯", "故事", "瓜子", "2348", "椅子", "内衣", "男 内衣", "男夹克", "饮料 ko", "x"}
	fmt.Println(len(url_params))
	for {
		url := "http://m.xylbh.cn/products/search.aspx?key=" + url_params[get_select_num(len(url_params))] // + strconv.Itoa(get_select_num(len(url_params)))
		go visit_search(url)
		time.Sleep(time.Millisecond * 20)
	}
}

func get_select_num(length_max int) int {
	rand.Seed(time.Now().UnixNano())
	return rand.Intn(length_max)
}

func visit_search(url string) {
	fmt.Println(url)
	defer func() {
		if p := recover(); p != nil {
			fmt.Printf("Recovered panic:%s\n", p)
		}
	}()

	// pic_url := "http://www.xylbh.cn:91/XYLPIC/goods_new/10/02/30/1002301836-L-1.jpg"
	resp, _ := http.Get(url)
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Println("status:", resp.Status)
	fmt.Println("lenth of body:", len(body))
}
